package com.alliky.core.net;

import com.alliky.core.base.BaseViewModel;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class BaseConsumer<VM extends BaseViewModel> implements Consumer<Disposable> {

    VM viewModel = null;
    boolean isLoading = true;

    public BaseConsumer(VM viewModel) {
        this.viewModel = viewModel;
    }

    public BaseConsumer(VM viewModel, boolean isLoading) {
        this.viewModel = viewModel;
        this.isLoading = isLoading;
    }

    @Override
    public void accept(Disposable disposable) throws Exception {
        if (viewModel != null) {
            viewModel.addSubscribe(disposable);
            if (isLoading) {
                viewModel.showLoading();
            }
        }
    }
}
